#!/bin/bash

# 强制拉取最新，覆盖本地
#git pull --force

# 设置代理
#go env -w GO111MODULE=on
#go env -w GOPROXY=https://goproxy.cn,direct

# 安装依赖
#go mod tidy

# 启动
srv_name="goods-srv"
chmod +x ./$srv_name
# 重启，如果服务已经启动则关闭重启
if pgrep -x $srv_name > /dev/null
then
  echo "${srv_name} is running"
  echo "shutting down ${srv_name}"
  if ps -A | grep $srv_name | awk '{print $1}' | xargs kill $1
    then
      echo "starting ${srv_name}"
      ./$srv_name > /dev/null 2>&1 &
      echo "start ${srv_name} success"
  fi
else
# 直接启动
  echo "starting ${srv_name}"
  ./$srv_name > /dev/null 2>&1 &
  echo "start ${srv_name} success"
fi